﻿// mlist.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "sqlist.h"
#include "lnode.h"
#include "dlinknode.h"
void SqListTest();
void LinkListTest();
void DLinkListTest();

using namespace dataStruct;
using namespace std;
int main()
{
    //SqListTest();
	//LinkListTest();
	DLinkListTest();
	system("pause");
	return 0;
}

void SqListTest()
{
	SqList* L;
	initList(L);
	char a[5] = { 'a', 'b', 'c', 'd', 'e' };
	for (int i = 0; i < 5; i++)
	{
		listInsert(L, i + 1, a[i]);
	}

	dispList(L);
	cout << listLength(L) << endl;
	cout << listEmpty(L) << endl;
	ElementType temp;
	getElem(L, 3, temp);
	cout << temp << endl;
	cout << locateElem(L, 'a') << endl;
	listInsert(L, 4, 'f');
	dispList(L);
	listDelete(L, 3, temp);
	cout << "delete 3: " << temp << endl;
	dispList(L);
	destoryList(L);

}

void LinkListTest()
{
	LinkNode* L;
	//InitList(L);
	ElementType a[5] = { 'a', 'b', 'c', 'd', 'e' };
	CreateListR(L, a, 5);
	DispList(L);
	cout << ListLength(L) << endl;
	cout << ListEmpty(L) << endl;
	ElementType temp;
	GetElem(L, 3, temp);
	cout << temp << endl;
	cout << LocateElem(L, 'a') << endl;
	ListInsert(L, 4, 'f');
	DispList(L);
	ListDelete(L, 3, temp);
	cout << "delete 3: " << temp << endl;
	DispList(L);
	DestoryList(L);

}

void DLinkListTest()
{
	DLinkNode* L;
	ElementType a[5] = { 'a', 'b', 'c', 'd', 'e' };
	CreateListR(L, a, 5);
	DispList(L);
	cout << ListLength(L) << endl;
	cout << ListEmpty(L) << endl;
	ElementType temp;
	GetElem(L, 3, temp);
	cout << temp << endl;
	cout << LocateElem(L, 'a') << endl;
	ListInsert(L, 4, 'f');
	DispList(L);
	ListDelete(L, 3, temp);
	cout << "delete 3: " << temp << endl;
	DispList(L);
	DestoryList(L);
}